package com.lancoo.ccas53.config;

import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * @ClassName MetaObjectHandlerConfig
 * @Description 加密敏感字段  应对鮀滨加密需求
 * @Author quin
 * @Date 2023/12/7 11:04
 */
@Primary
@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName("sensitiveTime", SecureUtil.md5(DateUtil.now()), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("sensitiveTime", SecureUtil.md5(DateUtil.now()), metaObject);
    }
}